package com.xunk.equipment.controller;

import com.alibaba.fastjson.JSONObject;
import com.xunk.common.core.enums.SupplierEnum;
import com.xunk.common.core.text.Convert;
import com.xunk.common.core.utils.HttpUtil;
import com.xunk.common.redis.service.RedisService;
import com.xunk.equipment.config.YikangConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.equipment.controller
 * @ClassName: DoorViewerController
 * @Author: luanzhiwei
 * @Description: 智能猫眼接口
 * @Date: 2021/4/2 13:47
 * @Version: 1.0
 */
@RestController
public class DoorViewerController {

    @Autowired
    private RedisService redisService;
    @Autowired
    private YikangConfig yikangConfig;


    @GetMapping(value = "/yikang/getPicture")
    public void getPicture(@RequestParam(name = "deviceSn") String deviceSn) {
        //待约定文件返回类型
        String redisKey = SupplierEnum.YIKANG.getSupplierName() + deviceSn;

        Object originFileUrl = redisService.getCacheMapValue(redisKey, "originFileUrl");
        Map<String, String> headers = new HashMap<>();
        String key = yikangConfig.getThirdPartyId() + "@" + yikangConfig.getAppKey();
        headers.put("x-api-key", Base64Utils.encodeToString(key.getBytes(StandardCharsets.UTF_8)));
        JSONObject jsonObject = HttpUtil.doGetstr(Convert.toStr(originFileUrl), headers);
    }


}
